/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sh.ndt.question.service;

import com.sh.ndt.exception.DAOException;
import com.sh.ndt.exception.ServiceException;
import com.sh.ndt.question.dao.QuestionDAO;
import com.sh.ndt.question.entity.Question;
import java.util.List;
import java.util.logging.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author Prashanth
 */
public class QuestionServiceImpl implements QuestionService {

    private static final long serialVersionUID = 1L;
    private static Logger LOGGER = Logger.getLogger(QuestionServiceImpl.class);
    QuestionDAO questionDao;

    public QuestionServiceImpl() {
        LOGGER.debug("Constructed QuestionServiceImpl............");
    }

    public QuestionServiceImpl(QuestionDAO questionDao) throws ServiceException {
        try {
            LOGGER.debug("*************** Inside QuestionServiceImpl Constructor ***************");
            this.questionDao = questionDao;

        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public List<Question> getQuestions(long categoryId) throws ServiceException {
        try {
            LOGGER.debug("*************** Inside QuestionServiceImpl getQuestions method ***************");

            return questionDao.getQuestions(categoryId);
        } catch (DAOException ex) {
            ex.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Question> getQuestions(long categoryId,int rowCount) throws ServiceException {
        try {
            LOGGER.debug("*************** Inside QuestionServiceImpl getQuestions method ***************");

            return questionDao.getQuestionsOnRowcount(categoryId, rowCount);
        } catch (DAOException ex) {
            ex.printStackTrace();
        }
        return null;
    }

    @Override
    public String markAsFailed(long scheduleId, long scheduleStatus) throws ServiceException {
        try {
            LOGGER.debug("*************** Inside markAsFailed getQuestions method ***************");

            return questionDao.markAsFailed(scheduleId,  scheduleStatus);
        } catch (DAOException ex) {
            ex.printStackTrace();
        }
        return null;
    }
    
    @Override
    public String markAsPassed(long scheduleId, long scheduleStatus) throws ServiceException {
        try {
            LOGGER.debug("*************** Inside markAsPassed getQuestions method ***************");

            return questionDao.markAsPassed(scheduleId,  scheduleStatus);
        } catch (DAOException ex) {
            ex.printStackTrace();
        }
        return null;
    }    

    @Override
    public String updateMockSession(long userId, long testId, int result, int creditPoint) {
        try {
            LOGGER.debug("*************** Inside markAsPassed getQuestions method ***************");

            return questionDao.updateMockSession(userId,  testId, result, creditPoint);
            
        } catch (DAOException ex) {
            ex.printStackTrace();
        }
        return null;    }
}
